import {
  registerDecorator,
  ValidationOptions,
  ValidationArguments,
} from 'class-validator';

export function IsDtoArray(
  property: string[],
  validationOptions?: ValidationOptions,
) {
  return function (object: Object, propertyName: string) {
    registerDecorator({
      name: 'IsDtoArray',
      target: object.constructor,
      propertyName: propertyName,
      constraints: [property],
      options: validationOptions,
      validator: {
        validate(value: any, args: ValidationArguments) {
          const [relatedPropertyName] = args.constraints;
          const relatedValue = (args.object as any)[relatedPropertyName];
          // return typeof value === 'string';
          console.log('value：参数', value);
          console.log('property', property);
          /* for(let v in property){
            console.log(v)
          } */
          // 1：获取到传过来的参数的每个对象里的key
          // 2：让对象的key 里是不是 有property数组里的key
          if (!Array.isArray(value) || value.length === 0) {
            return false;
          }
          const propertyObj = 0;
          for (let i = 0; i < value.length; i++) {
            const obj = value[i];
            console.log(obj);
            for(let o in obj){
               
            }
          }
          return false;
        }
      },
    });
  };
}
